﻿using DataServer.Entities;
using IsPay.Logic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IsPay.View
{
    public partial class ModifyLoginPwd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["USERID"] == null || Session["USERID"].ToString().Length <= 0)
            {
                Response.Write("<script>top.location='../Default.aspx'</script>");
            }
            if (Request.Params["txtpwdold"] == null)
            {
                return;
            }
            String stroldpwd = Request.Params["txtpwdold"].ToString();
            String strnewpwd = Request.Params["txtpwdnew1"].ToString();
            String strnewpwdchk = Request.Params["txtpwdnew2"].ToString();
            if (stroldpwd.Length == 0 && strnewpwd.Length == 0 && strnewpwdchk.Length == 0)
            {

            }else
            {
                if (stroldpwd.Length <= 0)
                {
                    lblmsg.Text = "请输入当前密码";
                    return;
                }
                if (strnewpwd.Length <= 0)
                {
                    lblmsg.Text = "请输入新密码";
                    return;
                }
                if (strnewpwdchk.Length <= 0)
                {
                    lblmsg.Text = "请再次输入校验新密码";
                    return;
                }
                if (!strnewpwd.Equals(strnewpwdchk))
                {
                    lblmsg.Text = "两次输入的密码不一致!";
                    return;
                }
                UserSer us = new UserSer();
                String struserid = Session["USERID"].ToString();
                UserProfile user = us.CheckUser(struserid, CodeMange.getMD5StringCode(stroldpwd));
                if (user == null || user.UserId.Length <= 0 || user.Pwd.Length <= 0)
                {
                    lblmsg.Text = "当前密码错误请重新输入";
                }else
                {
                    user.Pwd = CodeMange.getMD5StringCode(strnewpwd);
                    user.LastPCIp = Request.UserHostAddress;
                    user.LastPCName = Request.UserHostName;
                    user.LastPCMac = "";
                    List<UserProfile> lsuser = new List<UserProfile>();
                    lsuser.Add(user);
                    String strs=us.ModifyUsers(lsuser, struserid);
                    if (strs.Equals("OK"))
                    {
                        lblmsg.Text = "更改完成,下次登录请使用新密码!";
                    }else
                    {
                        lblmsg.Text = strs;
                    }
                }

            }
        }
    }
}